home *** CD-ROM | disk | FTP | other *** search
/ Cracking 2 / Cracking II..iso / Texty / crackme / CRUEME.BAK < prev    next >
Encoding:
Text File  |  1998-10-03  |  13.1 KB  |  511 lines

  1. ;-----------------------------------------------------------------------------------
  2. ; Title:              : CrueMe v1.0
  3. ; Author              : Cruehead
  4. ; Creation date       : 98-06-02
  5. ; Source release date : 98-10-10
  6. ;
  7. ; Description:
  8. ; This is the source code for yet another "CrackMe" program. This one
  9. ; has proven to be fairly hard to beat as I have only recieved two
  10. ; solutions. It features some polymorphic code to hide the real
  11. ; encryption and check routine. As soon as the real check has been executed
  12. ; the code will be overwritten with useless code, and a fake
  13. ; encryption/check routine will be executed. Every time the "Check It!"
  14. ; button is pressed the real encryption/check routine is beeing written
  15. ; to the correct place again. Before the real encryption/check routine is executed
  16. ; the string is fetched through the GetText message beeing sent.
  17. ; A breakpoint detection is made on the "GetDlgItemTextA" function as this
  18. ; is the routine that is used to fetch the string and then execute the fake test.
  19. ; All of this just to confuse the cracker into thinking he's on the right path
  20. ; when seeing the "No breakpoint..." message. Also the file called "CRUEME.DAT" has
  21. ; nothing to do whatsoever with the real check - it's only used as a red herring.
  22. ; Knowing this one can easily figure out that the "FileMon" detection is also only
  23. ; used as a red herring to distract the user from the real interesting piece of
  24. ; the code.
  25. ; Another thing is that all the functions used in the program are stored in a
  26. ; separate place thus making it a lookup table. This is only to confuse
  27. ; dead-listing crackers (and perhaps to cause some headaches).
  28. ; Conclusion: Alot of things to draw the cracker's attention to other useless
  29. ; pieces of the code. Also the ability to hide the real psw checking routine so the
  30. ; cracker wont see anything suspicious when browsing through the program using softice.
  31. ;
  32. ; I wont comment much of the code, and it might be a bit hard to follow everything
  33. ; but the program works as I described above and that is - if you ask me - the really
  34. ; interesting thing to know.
  35. ;
  36. ;
  37. ;
  38. ; Oh yeah! Perhaps you'd be interested to know that the password I choosed was
  39. ; "Cracking4U". Alot of other passwords will pass as well though.
  40. ;-----------------------------------------------------------------------------------
  41.  
  42. .386
  43. locals
  44. jumps
  45. .model flat,STDCALL
  46.  
  47. ;----------------------------------------------------------
  48. ;Structure, EQU, Includefiles declaration
  49. ;----------------------------------------------------------
  50.  
  51. include win32.inc           ; some 32-bit constants and structures
  52. L equ <LARGE>
  53.  
  54. IDD_STAT         EQU 1010
  55. IDD_CLOSE         EQU 1004
  56. IDD_GO             EQU 1003
  57. IDD_EDIT1         EQU 1002
  58. IDI_ICON1         EQU 100
  59.  
  60. TRUE             EQU 1
  61. FALSE              EQU 0
  62. NULL             EQU 0
  63.  
  64. ;----------------------------------
  65. ; Our Variables
  66. ;----------------------------------
  67.  
  68. .data
  69.  
  70. szTitleName      db '',0
  71. szClassName      db 'ASMCLASS32',0
  72. lppaint          PAINTSTRUCT <?>
  73. msg              MSGSTRUCT   <?>
  74. wc               WNDCLASS    <?>
  75. tm                 TEXTMETRIC  <?>
  76. RC                 RECT         <?>
  77. Systime             SYSTEMTIME  <?>
  78.  
  79. dlg_start        db 'DLG_START',0
  80. Buffert             db 7,41,25,22,37,6,1,12,35,24,11,8,23,14,5,42,33,38,27,3,21,4,39,10,20,26,19,28,32,40,31,29,34,9,17,36,15,18,13,30,2,16
  81.  
  82. psw                 db 14 dup (0)
  83. fakebuff         db 8 dup (0)
  84. loopindex         db 0ffh
  85.  
  86. FileFakePsw         db 0ffh,077h,088h,066h,099h,055h,0aah,044h,0bbh,033h,0cch,022h,0ddh,011h,0eeh
  87.  
  88. Flagst             dd 0c0h            ; Open with these flags! (RWE)
  89.  
  90. FileMon             db 05dh,0a5h,0b9h,0e4h,0d4h,080h,019h,0a5h,0b1h,095h,080h,035h,0bdh,0b9h,0a5h,0d1h,0bdh,0c9h,0
  91. ProcID             dd 0
  92. handle             dd 0
  93.  
  94. WhyNot1             dd 015263748h
  95. WhyNot2             dd 0596a7b8ch
  96. NoNeed1             dd 0
  97. NoNeed2             dd 0
  98. length             dd 0
  99.  
  100. Filename         db 'CRUEME.DAT',0
  101. filehandle         dd 0
  102. readbuffer         db 15 dup (0)
  103. somanyread         dd 0
  104.  
  105. NotUsedYet1         dd 0
  106. NotUsedYet2         dd 0
  107.  
  108. FileHeader         db "This is the end - My only friend the end!",0
  109. FileMissing         db 'AAARGH! Where is my CRUEME.DAT file???',13
  110.                  db '    I cant go on without my beloved file!',0
  111.  
  112. tempflag         db 0
  113. statwait         db 'Status: Waiting for input',0
  114. statyes             db 'Correct password - Good work!',0
  115. statno             db 'False password - Try again',0
  116. statyescopy         db 30 dup (0)
  117.  
  118. siceHeader         db 'Breakpoints - just say no!',0
  119. nosice             db "So - You're trying to put a breakpoint on GetDlgItemTextA, eh?",13
  120.                  db "You know - I cant allow you to do that... that would make",13
  121.                  db "things easy for you, so...sorry mate - This has to end right now!",0
  122.  
  123. XorSeed             db 0
  124. chooseofs         dd 0
  125. para1              dd 0
  126. para2              dd 0
  127. return             dd 0
  128.  
  129. oldprot             dd 0
  130. paddress          dd 0400000h
  131. pseudo             dd 0
  132. patchhere         dd 0802448h                        ; / 2 = 0401224h
  133. regsize              dd 4096
  134. byteswritten     dd 0
  135.  
  136. RealRoutine         db 052h,06ah,00eh,06ah,00dh,068h,0eah,003h,000h,000h,0ffh,075h,008h,0b0h,025h
  137.                  db 0ffh,015h,064h,023h,040h,000h,0e8h,035h,009h,000h,000h,050h,0bfh,001h,000h
  138.                  db 000h,000h,0e8h,0fdh,008h,000h,000h
  139.  
  140. FakeRoutine         db 0b1h,096h,055h,08bh,0ech,051h,083h,0ech,03ch,066h,0ffh,075h,008h,0ffh,075h,00ch,098h,0b1h,095h,08bh
  141.                  db 0ech,08bh,075h,00ch,00bh,0f6h,08dh,07dh,0b8h,057h,00bh,0ffh,0c1h,0e0h,004h,003h,0c2h
  142. hInst             dd 0
  143. hMenu             dd 0
  144. hDlg              dd 0
  145.  
  146. ;-----------------------------------
  147. ; Startup
  148. ;-----------------------------------
  149.  
  150. .code
  151.  
  152. ;---------------------------------------------------------
  153. ; This is where control is received from the loader.
  154. ;---------------------------------------------------------
  155.  
  156. start:
  157.         mov        chooseofs,offset choose
  158.  
  159.         push    offset Systime
  160.         call    GetLocalTime
  161.         lea        ebx,[ebx*4]
  162.         shr        patchhere,1
  163.         mov        ax, Systime.wMilliseconds        ;Get Milliseconds in AX
  164.         mov        XorSeed,al                        ;AL = our XorSeed
  165.         call    XorBuffer
  166.  
  167.         add        eax,5
  168.         lea        eax,[eax*4]
  169.         add        eax,5
  170.  
  171.         call    FixShutDown
  172.  
  173.         push    L 0
  174.         push    L 080h
  175.         push     L 3
  176.         push    L 0
  177.         push    L 0
  178.         push    0C0000000h
  179.         push    offset Filename
  180.         mov        al,31
  181.         call    [chooseofs]                        ;CreateFileA = 8
  182.         cmp        eax,-1
  183.         jnz        Goon
  184.  
  185.         push    L MB_ICONEXCLAMATION
  186.         push    offset FileHeader
  187.         push    offset FileMissing
  188.         push    0
  189.         mov        al,26
  190.         call    [chooseofs]                        ;MessageBoxA = 33
  191.  
  192.         push    [msg.msWPARAM]
  193.         mov        al,10
  194.         call    [chooseofs]                        ;ExitProcess = 34
  195.  
  196.         Goon:
  197.         mov        filehandle,eax
  198.         mov     eax,15
  199.         mov     ebx,offset readbuffer
  200.         push     L 0
  201.         push     offset somanyread
  202.         push     eax
  203.         push     ebx
  204.         push     [filehandle]
  205.         mov        al,29
  206.         call    [chooseofs]                        ;ReadFile = 14
  207.  
  208.         push    [filehandle]
  209.         mov        al,42
  210.         call    [chooseofs]                        ;CloseHandle = 7
  211.  
  212.         push    L 0
  213.         mov        al,19
  214.         call    [chooseofs]                          ;GetModuleHandle = 10
  215.         mov        [hInst], eax
  216.  
  217.         push    L 0
  218.         push    offset szClassName
  219.         mov        al,39
  220.         call    [chooseofs]                          ;FindWindow = 22
  221.         or      eax,eax                 
  222.         jz      reg_class                       ;More programs than one?
  223.         ret                                     ;No, only one open at time
  224.  
  225. reg_class:
  226.  
  227.         mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
  228.         mov     [wc.clsLpfnWndProc], offset WndProc
  229.         mov     [wc.clsCbClsExtra], 0
  230.         mov     [wc.clsCbWndExtra], 0
  231.  
  232.         mov     eax, [hInst]
  233.         mov     [wc.clsHInstance], eax
  234.  
  235.         push    IDI_ICON1
  236.         push    eax
  237.         mov        al,5
  238.         call    [chooseofs]                        ;LoadIcon = 18
  239.         mov     [wc.clsHIcon], eax
  240.  
  241.         push    L IDC_ARROW             
  242.         push    L 0
  243.         mov        al,14
  244.         call    [chooseofs]                        ;LoadCursor = 32
  245.         mov     [wc.clsHCursor], eax
  246.  
  247.         push    L 0                     
  248.         push    offset Main_DlgProc     
  249.         push    L 0
  250.         push    offset dlg_start                ;Startup dlg resource (main resource)
  251.         push    [hInst]
  252.         mov        al,18
  253.         call    [chooseofs]                        ;DialogBoxParamA = 20
  254.         jmp     finish                          ;Back main window
  255.  
  256. msg_loop:
  257.         push    L 0
  258.         push    L 0
  259.         push    L 0
  260.         push    offset msg
  261.         mov        al,36
  262.         call    [chooseofs]                        ;GetMessage = 1
  263.         call    choose
  264.  
  265.         cmp     ax, 0
  266.         je      end_loop
  267.  
  268.         push    offset msg
  269.         mov        al,9
  270.         call    [chooseofs]                        ;TranslateMessage = 9
  271.  
  272.         push    offset msg
  273.         mov        al,6
  274.         call    [chooseofs]                        ;DispatchMessage = 15
  275.  
  276.         jmp     msg_loop
  277.  
  278. end_loop:
  279.         push    [msg.msWPARAM]
  280.         mov        al,10
  281.         call    [chooseofs]                        ;ExitProcess = 34
  282.  
  283. ;----------------------------------------------------------------------------
  284. ; WARNING: Win32 requires that EBX, EDI, and ESI be preserved!  
  285. ;
  286. ; In this part we will put the events we want to respond on.
  287. ; Key, MouseButtons, Resize, Menu, Commands.... (look at the win32.inc)
  288. ; You can leave the above without changes a modify the next part only
  289. ;----------------------------------------------------------------------------
  290.  
  291. WndProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  292.         push    esi
  293.         push    edi
  294.         push    ebx
  295.         jmp     defwndproc
  296. defwndproc:
  297.         push    [lparam]
  298.         push    [wparam]
  299.         push    [wmsg]
  300.         push    [hwnd]
  301.         call    DefWindowProc
  302.         jmp     finish
  303.  
  304. finish:
  305.         pop     ebx                             ;Remember we must restore these registers
  306.         pop     edi                             ;Because the OS need them
  307.         pop     esi
  308.         ret
  309.  
  310. WndProc          endp
  311.  
  312. public WndProc
  313.  
  314.  
  315. ;----------------------
  316. ;Start Dialog
  317. ;----------------------
  318.  
  319. Main_DlgProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  320.  
  321.         push    ebx
  322.         push    esi
  323.         push    edi
  324.  
  325.         cmp     [wmsg],WM_COMMAND                ;Respond to buttons
  326.         je      main_command
  327.         cmp     [wmsg], WM_CLOSE                ;Respond to if we want to shut it down
  328.         je      main_dlgdestroy
  329.                        
  330.         mov     eax,FALSE
  331.  
  332. main_finish:
  333.         pop     edi
  334.         pop     esi
  335.         pop     ebx
  336.         ret
  337.  
  338. updatestat:
  339.         Call     PolySetup
  340.  
  341.         push    offset statwait
  342.         push    IDD_STAT
  343.         push    [hwnd]
  344.         mov        al,21
  345.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  346.  
  347.         mov        tempflag,1        
  348.         mov        eax,TRUE
  349.         jmp        main_finish
  350.         
  351. ;---------------------------------
  352. ;HERE IS WHERE THE FUN PART BEGINS
  353. ;---------------------------------
  354.  
  355. main_go:                        
  356.  
  357.         mov        edx,offset psw
  358.         lea        ebx,[eax*4]
  359.         add        ebx,5
  360.         add        ebx,edx
  361.  
  362.         push    edx
  363.         push    L 14
  364.         push    L WM_GETTEXT
  365.         push    L IDD_EDIT1
  366.         push    [hwnd]
  367.         mov        al,37
  368.         call    [chooseofs]                        ;SendDlgItemMessageA = 6
  369.         call    RealProt
  370.         push    eax
  371.  
  372.         mov        edi,1                            ;Edi=1 --> Write FakeCode
  373.         call    PolyWrite
  374.  
  375.         mov        ecx,8
  376.         lea        edi,readbuffer
  377.         lea        esi,FileFakePsw        
  378.         fakefake:
  379.         mov        al, byte ptr [edi]
  380.         mov        bl, byte ptr [esi]
  381.         xor        al,bl
  382.         rol        al,1
  383.         mov        byte ptr [esi],al
  384.         inc        edi
  385.         inc        esi
  386.         loop    fakefake
  387.  
  388.  
  389.         pop        eax
  390.         test    eax,eax
  391.         je        Noneedforthis
  392.  
  393.         lea        edi,GetDlgItemTextA
  394.         push    10
  395.         push    offset psw        
  396.         push    IDD_EDIT1
  397.         push    [hwnd]
  398.  
  399.         push    ds
  400.         push    cs
  401.         pop        ds
  402.         mov        edi,[edi+2]                        ;Get DLL function jmp address
  403.         mov        edi,[edi]                        ;Get DLL function real address
  404.         mov        eax,[edi]                        ;Get first bytes of DLL function
  405.         pop        ds
  406.         and     eax,0FFh                        ;Save only the first byte
  407.         cmp        eax,0CCh                        ;It this function BPX'ed?
  408.         jne        NoBPX
  409.  
  410.         push    L MB_ICONEXCLAMATION
  411.         push    offset siceHeader
  412.         push    offset nosice
  413.         push    0
  414.         mov        al,26
  415.         call    [chooseofs]                        ;MessageBoxA = 33
  416.  
  417.         push    [msg.msWPARAM]
  418.         mov        al,10
  419.         call    [chooseofs]                        ;ExitProcess = 34
  420.  
  421.         NoBPX:
  422.         call    edi
  423.  
  424.         call    fakeprot
  425.         test    eax,eax
  426.         je        fakenotvalid
  427.  
  428.         push    offset statyes
  429.         push    IDD_STAT+1
  430.         push    [hwnd]
  431.         mov        al,21
  432.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  433.  
  434.         fakenotvalid:
  435.         push    offset statno
  436.         push    IDD_STAT
  437.         push    [hwnd]
  438.         mov        al,21
  439.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  440.         
  441.         Noneedforthis:
  442.         xor        edi,edi
  443.         call    PolyWrite                        ;Edi=0 --> Write RealProtScheme
  444.         mov        eax,TRUE
  445.         jmp        main_finish
  446.  
  447.  
  448. main_command:
  449.         cmp        tempflag,0
  450.         je        updatestat
  451.         cmp        [wparam],IDD_GO                    ;User clicked on "check" button?
  452.         je        main_go
  453.         cmp     [wparam],IDD_CLOSE
  454.         jne     main_nothing
  455.  
  456. main_dlgdestroy:
  457.         push    L 0             
  458.         push    [hwnd]
  459.         mov        al,3
  460.         call    [chooseofs]                         ;CloseDialog = 30
  461.  
  462.         mov     eax,TRUE        
  463.         jmp     main_finish
  464.  
  465. main_nothing:
  466.  
  467.         push    offset FileMon
  468.         push     L 0
  469.         mov        al,39
  470.         call    [chooseofs]                          ;FindWindow = 22
  471.         test    eax,eax        
  472.         jz        noclose
  473.  
  474.         push     offset ProcID
  475.         push     eax            
  476.         mov        al,30
  477.         call    [chooseofs]                        ;GetWindowThreadProcessId = 23
  478.         test     eax,eax
  479.         jz       noclose
  480.  
  481.         push     [ProcID]                        ;Owner process ID
  482.         push     L 0
  483.         push     offset Flagst                    ;Flags = Read/Write
  484.         mov        al,8
  485.         call    [chooseofs]                        ;OpenProcess = 17
  486.         test     eax,eax
  487.         jz         noclose
  488.         mov        handle,eax
  489.  
  490.         push    offset ProcID
  491.         push    eax
  492.         mov        al,32
  493.         call    [chooseofs]                        ;GetExitCodeProcess = 11
  494.         test    eax,eax
  495.         jz        noclose
  496.             
  497.         push    [ProcID]
  498.         push    [handle]
  499.         mov        al,13
  500.         call    [chooseofs]                        ;TerminateProcess = 40
  501.  
  502. noclose:
  503.  
  504.         mov     eax,FALSE
  505.         jmp     main_finish
  506.  
  507. Main_DlgProc    endp
  508. public Main_DlgProc
  509.        include morefunc.asm
  510.  
  511. end start
  512.